import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

# options = webdriver.ChromeOptions()
# options.page_load_strategy = "normal"  # 等待页面完全加载
# 创建浏览器驱动对象
driver = webdriver.Chrome()
driver.implicitly_wait(5)
url = r"https://www.baidu.com/"
driver.get(url)
try:
    search = driver.find_element(By.CSS_SELECTOR, "#head_wrapper #kw")
    search.send_keys("blbl", Keys.ENTER)
    time.sleep(3)
    driver.find_element(By.LINK_TEXT, "哔哩哔哩").click()
    driver.switch_to.window(driver.window_handles[1])
    search = driver.find_element(By.XPATH, "//input[@class='nav-search-input']")
    search.send_keys("凡人修仙传", Keys.ENTER)
    time.sleep(3)
    driver.switch_to.window(driver.window_handles[2])
    driver.find_element(By.LINK_TEXT, "立即观看").click()
    driver.maximize_window()
    driver.switch_to.window(driver.window_handles[3])
    time.sleep(3)
    driver.find_element(By.XPATH, "//div[@aria-label='全屏']").click()

except Exception as e:
    print(e)
input("关闭按任意键 回车:")
for h in driver.window_handles:
    driver.switch_to.window(h)
    driver.close()
driver.quit()
